package leetcode;

/**
 * Created by Ghost on 2014/11/11.
 */
public class Find_Minimum_in_Rotated_Sorted_Array {
    public int findMin(int[] num) {
        int begin = 0,end = num.length-1;
        if(num[begin]<num[end])
            return num[begin];
        while(begin<end-1){
            int mid = (begin+end)/2;
            if(num[begin]<num[mid]){
                begin = mid;
            }
            else{
                end = mid;
            }
        }
        return num[begin]<num[end]?num[begin]:num[end];
    }
    public static void main(String[] args){
        Find_Minimum_in_Rotated_Sorted_Array find_minimum_in_rotated_sorted_array = new Find_Minimum_in_Rotated_Sorted_Array();
        System.out.println(find_minimum_in_rotated_sorted_array.findMin(new int[]{5, 0, 1, 2, 3, 4}));
    }
}
